﻿Public Class FormCheckGjb
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Public sys_id As String
    Public procedure_no As String
    Public group_no As String
    Public b_gt_sys_id As String
    Dim p_no As Integer
    Dim objGtProcedureOperatedDetails As New clsGtProcedureOperatedDetails
    Dim dr1 As DataRow()
    Dim dr2 As DataRow()
    Dim dr3 As DataRow()
    Private Sub FormCheckOper_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        p_no = Integer.Parse(procedure_no)
        If p_no = 2 Then
            txt_num1.Enabled = False
        End If
        If p_no = 3 Then
            txt_num1.Enabled = False
            txt_num2.Enabled = False
        End If
        Dim dtt As DataTable = objGtProcedureOperatedDetails.getGtProcedureOperatedDetailsByGroupNo(b_gt_sys_id, group_no)
        dr1 = dtt.Select("procedure_no = '1'")
        If dr1.Length > 0 Then
            txt_num1.Value = Integer.Parse(dr1(0)("oper_num").ToString())
        Else
            MsgBox("请确保入料数走完所有工序")
        End If
        dr2 = dtt.Select("procedure_no = '2'")
        If dr2.Length > 0 Then
            txt_num2.Value = Integer.Parse(dr2(0)("oper_num").ToString())
        Else
            MsgBox("请确保入料数走完所有工序")
        End If
        dr3 = dtt.Select("procedure_no = '3'")
        If dr3.Length > 0 Then
            txt_num3.Value = Integer.Parse(dr3(0)("oper_num").ToString())
        Else
            MsgBox("请确保入料数走完所有工序")
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If txt_num1.Value > 0 And txt_num2.Value > 0 And txt_num3.Value > 0 And
            txt_ng_num1.Value >= 0 And txt_ng_num2.Value >= 0 And txt_ng_num3.Value >= 0 Then

            Dim rtn As Integer
            rtn = objGtProcedureOperatedDetails.updateGtProcedureOperatedDetailsGjb(
                                txt_num1.Value, txt_ng_num1.Value, dr1(0)("sys_id").ToString(),
                                txt_num2.Value, txt_ng_num2.Value, dr2(0)("sys_id").ToString(),
                                txt_num3.Value, txt_ng_num3.Value, dr3(0)("sys_id").ToString())
            If rtn <> -2 Then
                MsgBox("保存成功")
            Else
                MsgBox("保存失败")
            End If
        Else
            MsgBox("入料数量需＞0")
        End If

    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_num2.MouseDown, txt_num3.MouseDown, txt_num1.MouseDown, txt_ng_num3.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub txt_num2_MouseUp(sender As Object, e As MouseEventArgs) Handles txt_num2.MouseUp
        If txt_num2.Value > txt_num1.Value Then
            MsgBox("喷砂清洗入料数 > 校平入料数")
        Else
            txt_ng_num1.Value = txt_num1.Value - txt_num2.Value
        End If
    End Sub

    Private Sub txt_num3_MouseUp(sender As Object, e As MouseEventArgs) Handles txt_num3.MouseUp
        If txt_num3.Value > txt_num2.Value Then
            MsgBox("六工位入料数 > 喷砂清洗入料数")
        Else
            txt_ng_num2.Value = txt_num2.Value - txt_num3.Value
        End If
    End Sub

    Private Sub txt_ng_num3_MouseUp(sender As Object, e As MouseEventArgs) Handles txt_ng_num3.MouseUp
        If txt_ng_num3.Value > txt_num3.Value Then
            MsgBox("六工位不合格数 > 六工位入料数")
        End If
    End Sub

    Private Sub txt_num2_TextChanged(sender As Object, e As EventArgs) Handles txt_num2.TextChanged
        If (UcDigitalKeyboard1 Is Nothing) = False Then
            UcDigitalKeyboard1.Hide()
        End If
        If txt_num1.Value > 0 Then
            If txt_num2.Value > txt_num1.Value Then
                MsgBox("喷砂清洗入料数 > 校平入料数")
            Else
                txt_ng_num1.Value = txt_num1.Value - txt_num2.Value
            End If
        Else
            MsgBox("校平入料数需 > 0")
        End If
    End Sub

    Private Sub txt_num3_TextChanged(sender As Object, e As EventArgs) Handles txt_num3.TextChanged
        If (UcDigitalKeyboard1 Is Nothing) = False Then
            UcDigitalKeyboard1.Hide()
        End If
        If txt_num2.Value > 0 Then
            If txt_num3.Value > txt_num2.Value Then
                MsgBox("六工位入料数 > 喷砂清洗入料数")
            Else
                txt_ng_num2.Value = txt_num2.Value - txt_num3.Value
            End If
        Else
            MsgBox("喷砂清洗入料数需 > 0")
        End If
    End Sub
End Class